package com.neurotech.pcc.vm

import android.arch.lifecycle.MediatorLiveData
import android.arch.lifecycle.ViewModel
import com.neurotech.pcc.dummy.RemoteModel


/**
 * Created by shenhua on 2018/10/15.
 *
 * @author shenhua
 * Email shenhuanet@126.com
 */
class RemotesViewModel(
        private val remotesRepository: RemotesRepository
) : ViewModel() {

    private val remoteModel = MediatorLiveData<List<RemoteModel>>()

    init {
        val remotes = remotesRepository.getRemotes()
        remoteModel.addSource(remotes, remoteModel::setValue)
    }

    fun getRemotes() = remoteModel

    fun insert(remoteModel: RemoteModel) {
        remotesRepository.insert(remoteModel)
    }

    fun delete(remoteModel: RemoteModel) {
        remotesRepository.delete(remoteModel)
    }

    fun update(remoteModel: RemoteModel) {
        remotesRepository.update(remoteModel)
    }

}